package com.anteater.eattheant.view;

import javax.microedition.khronos.opengles.GL10;

import com.anteater.eattheant.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.opengl.GLUtils;

public class Escape extends Group {

	private final short i;
	private final short j;

	public Escape(short i, short j, GL10 gl, Context context) {
		this.i = i;
		this.j = j;

		Square square = new Square(1.0f);
		square.setTexture(new float[] { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
				1.0f, 1.0f }, loadTexture(gl, context));
		add(square);
	}

	public short getI() {
		return i;
	}

	public short getJ() {
		return j;
	}
	
	private int loadTexture(GL10 gl, Context context) {
		int texture[] = new int[1];

		gl.glGenTextures(1, texture, 0);

		Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),
				R.drawable.escape_64x64);

		gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]);

		gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
				GL10.GL_NEAREST);
		gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,
				GL10.GL_NEAREST);

		GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);

		bitmap.recycle();

		return texture[0];
	}
}
